{% extends 'base.html' %}
<!-- {% load url_utils %} -->
{% load url_utils %}
{% block content %}
<div class="right">
    <h2 style="text-align: center; padding: 10px;"> {{ request.user.student.student_name }}  成绩列表</h2>
    <div class="bottom">
        <table>
            <thead>
                <tr>
                    <!-- <th><input type="checkbox" id="select-all"></th> -->
                    <th>考试名称</th>
                    <th>姓名</th>
                    <th>班级</th>
                    <th>学号</th>
                    <th>语文</th>
                    <th>数学</th>
                    <th>英语</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for score in scores %}
                <tr>
                    <!-- <td><input type="checkbox" name="score_ids" value="{{ score.id }}"></td> -->
                    <td>{{ score.title }}</td>
                    <td>{{ score.student_name }}</td>
                    <td>{{ score.grade.grade_name }}</td>
                    <td>{{ score.student_number }}</td>
                    <td>{{ score.chinese_score }}</td>
                    <td>{{ score.math_score }}</td>
                    <td>{{ score.english_score }}</td>
                    <td>
                        <a href="{% url 'score_detail' score.pk %}" class="text-detail"> 查看</a>
                </tr>
                {% empty %}
                <tr>
                    {% if not request.user.student %}
                    <!-- <td style="border: 2px solid red; padding: 8px;" colspan="9">
                        <span style="color: red; font-weight: bold;">该页面仅允许登录学生账号访问</span>
                    </td> -->
                    <script>
                        // window.location.href = "{% url 'user_login' %}";
                        Swal.fire({
                            icon: 'error',
                            title: '无权限访问！！！该页面仅允许登录学生账号访问',
                            confirmButtonText: '好的', 
                        }).then((result)=>{
                            if(result.isConfirmed){
                                window.location.href = "{% url 'score_list' %}";
                            }
                            //  如果需要区分关闭类型可以这样：
                            // if (result.dismiss === Swal.DismissReason.close) {
                            //     // 点击外部关闭
                            //     window.location.href = "{% url 'score_list' %}";
                            // } else if (result.dismiss === Swal.DismissReason.esc) {
                            //     // 按ESC键关闭
                            //     window.location.href = "{% url 'score_list' %}";
                            // }

                            // 统一处理所有关闭情况
                            if (result.dismiss) {  // 任何关闭方式都会触发
                                window.location.href = "{% url 'score_list' %}";
                            }
                        })
                    </script>
                    {% else %}
                    <td colspan="9">暂无学生成绩信息</td>
                    {% endif %}
                </tr>
                {% endfor %}
            </tbody>
        </table>
        <div class="pagination">
            <div>
                <div>
                    <span>第{{ page_obj.number }}页/共{{ page_obj.paginator.num_pages }}页</span>
                    {% if page_obj.has_previous %}
                        <a href="?{% search_url request page=1 %}">首页</a>
                        <a href="?{% search_url request page=page_obj.previous_page_number %}">上一页</a>
                    {% endif %}
                    
                    {% if page_obj.has_next %}
                        <a href="?{% search_url request page=page_obj.next_page_number %}">下一页</a>
                        <a href="?{% search_url request page=page_obj.paginator.num_pages %}">尾页</a>
                    {% endif %}
                </div>
            </div>

        </div>
    </div>
</div>

{% include 'scores/score_list_script.html' %}

{% endblock %}

